﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace SocketLibrary
{
    /// <summary>
    /// 接受到一个命令消息时触发的事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void CommandReceivedEventHandler(object sender, CommandEventArgs e);

    /// <summary>
    /// 服务器关闭一个连接时触发的事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void ServerDisconnectedEventHandler(object sender, SocketEventArgs e);

    /// <summary>
    /// 客户端关闭一个连接触发
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void ClientDisconnectedEventHandler(object sender, EventArgs e);

    /// <summary>
    /// 网络断开触发的事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void NetworkDeadEventHandler(object sender, EventArgs e);

    /// <summary>
    /// 网络恢复正常触发的事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void NetworkAlivedEventHandler(object sender, EventArgs e);

    /// <summary>
    /// 接受一个命令消息
    /// </summary>
    public class CommandEventArgs : EventArgs
    {
        private CommandInfo t_cmd;
        /// <summary>
        /// 命令消息
        /// </summary>
        public CommandInfo CmdInfo
        {
            get { return t_cmd; }
        }

        /// <summary>
        /// 构造一个命令消息
        /// </summary>
        /// <param name="i_cmd"></param>
        public CommandEventArgs(CommandInfo i_cmd)
        {
            this.t_cmd = i_cmd;
        }
    }

    /// <summary>
    /// 关闭一个连接对象
    /// </summary>
    public class SocketEventArgs : EventArgs
    {
        private Socket m_socket;
        /// <summary>
        /// 连接上来的IP
        /// </summary>
        public IPAddress IP
        {
            get { return ((IPEndPoint)this.m_socket.RemoteEndPoint).Address; }
        }
        /// <summary>
        /// 连接上来的端口
        /// </summary>
        public int Port
        {
            get { return ((IPEndPoint)this.m_socket.RemoteEndPoint).Port; }
        }
        /// <summary>
        /// 构造一个连接对象
        /// </summary>
        /// <param name="clientManagerSocket"></param>
        public SocketEventArgs(Socket i_socket)
        {
            this.m_socket = i_socket;
        }
    }
    
}
